//final和const
class Address {
  String city;
  String state;
  Address(this.city, this.state);
}

main() {
  final a1 = '1234';
  //a1 = 'AAA'; //编译期出错
  print(a1);

  final constantMap = const {
    2: 'helium',
    10: 'neon',
    18: 'argon',
  };
  print(constantMap);
  //constantMap[2] = 'else'; error

  final List<String> items = <String>[];
  items.insert(0, 'item-1');
  print(items);

  //Thanks: https://medium.com/dartlang/an-intro-to-immutability-with-dart-d4de871865c7
  //In Dart, const is both an immutable binding and an immutable object:
  final user = const {'name': 'Joe'};

  // Static error: "Constant variables cannot be assigned a value".
  //user = {};

  // Runtime error: "Unsupported operation: Cannot modify unmodifiable Map".
  //user['name'] = 'Jill';
  print(user);

  //The address variable is marked as final, so it will always point to the object instantiated by
  //the new Address("anytown", "hi") constructor. However, the object itself has state that is mutable,
  //so it's perfectly valid to change the city. The only thing prevented by final is reassigning the
  //address variable.
  final address = new Address("anytown", "hi");
  address.city = 'waikiki';
  print(address.city); // waikiki
}
//EOP
